/**
 * 
 */
package com.vision.core.cl.util;

import com.sencha.gxt.widget.core.client.form.Field;
import com.sencha.gxt.widget.core.client.form.validator.MaxLengthValidator;
import com.sencha.gxt.widget.core.client.form.validator.MinLengthValidator;
import com.sencha.gxt.widget.core.client.form.validator.RegExValidator;

/**
 * @author Mark
 *
 */
public class FieldUtils {
	
	public static void minMaxOf(Field<String> field, Integer min, Integer max) {
		minOf(field, min);
		maxOf(field, max);
	}
	
	public static void minOf(Field<String> field, Integer min) {
		if (min != null)
			field.addValidator(new MinLengthValidator(min));
	}
	
	public static void maxOf(Field<String> field, Integer max) {
		if (max != null)
			field.addValidator(new MaxLengthValidator(max));
	}
	
	public static void regex(Field<String> field, String regex) {
		field.addValidator(new RegExValidator(regex));
	}
	
	public static void regex(Field<String> field, RegExValidator validator) {
		field.addValidator(validator);
	}

}
